package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.OrderInitiate;
import com.ruoyi.system.service.IOrderInitiateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/initiate")
public class OrderInitiateController extends BaseController
{
    @Autowired
    private IOrderInitiateService orderInitiateService;

    /**
     * 查询订单信息列表
     */
    @RequiresPermissions("order:initiate:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderInitiate orderInitiate)
    {
        startPage();
        List<OrderInitiate> list = orderInitiateService.selectOrderInitiateList(orderInitiate);
        return getDataTable(list);
    }

    /**
     * 导出订单信息列表
     */
    @RequiresPermissions("order:initiate:export")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderInitiate orderInitiate)
    {
        List<OrderInitiate> list = orderInitiateService.selectOrderInitiateList(orderInitiate);
        ExcelUtil<OrderInitiate> util = new ExcelUtil<OrderInitiate>(OrderInitiate.class);
        util.exportExcel(response, list, "订单信息数据");
    }

    /**
     * 获取订单信息详细信息
     */
    @RequiresPermissions("order:initiate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderInitiateService.selectOrderInitiateById(id));
    }

    /**
     * 新增订单信息
     */
    @RequiresPermissions("order:initiate:add")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping

    public AjaxResult add(@RequestBody OrderInitiate orderInitiate)
    {
        return toAjax(orderInitiateService.insertOrderInitiate(orderInitiate));
    }

    /**
     * 修改订单信息
     */
    @RequiresPermissions("order:initiate:edit")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderInitiate orderInitiate)
    {
        return toAjax(orderInitiateService.updateOrderInitiate(orderInitiate));
    }

    /**
     * 删除订单信息
     */
    @RequiresPermissions("order:initiate:remove")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderInitiateService.deleteOrderInitiateByIds(ids));
    }
}
